"""此文件为全局共享变量"""
import os
import pickle#序列化
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *      #无边框,选框,动画
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import subprocess

def _init():
    """初始化"""
    global SeerStateValue
    SeerStateValue = {"Task":None,"Zhan":None,"SeerDm":None,"SeerPVP":None}

def set_value(key,value):
    """定义一个全局变量"""
    SeerStateValue[key] = value

def get_value(key,defValue=None):
    """获得一个全局变量,不存在则返回默认值"""
    return SeerStateValue[key]

def 退出():
    os._exit(0)    

def 弹窗(任务ID='',文字='这是一个弹窗'):
    """注意尽量不要放在job里面否则会弹出很多弹窗"""
    class MyWindows(QMainWindow):
        def __init__(self):
            super().__init__()
            self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowStaysOnTopHint)
    _w = MyWindows()
    QMessageBox.information(_w,"消息",文字)

def 刷新():
    """按f5刷新，仅仅Chika能用"""
    fp = open("刷新.vbs",'w')
    _str = 'Set objShell = CreateObject("Wscript.Shell") \nobjShell.SendKeys "{' + 'F5}"'
    fp.write(_str)
    fp.close()
    subprocess.call ('cscript 刷新.vbs')

def 战斗(_出招表):
    """开启战斗模块"""
    task = get_value('Task')
    task.addTask("ZhanDou","",_出招表)
    
def 背包(_精灵):
    """开启背包模块"""
    task = get_value('Task')
    task.addTask("BeiBao","",_精灵)
    

def Fun(task_id="0001",task_id2="0001_1",_isClickImage=1):
    task = get_value('Task')
    return task.Fun(task_id,task_id2,_isClickImage)
def Logs(isGet="get",task_id="0000",task_id2="变量名",_str="Set"):
    task = get_value('Task')
    return task.Logs(isGet,task_id,task_id2,_str)

def pickle_cun(filename,data01):
    #序列化保存文件
    with open(filename,'wb') as f:
        pickle.dump(data01,f)

def pickle_qu(filename):
    #序列化读取文件
    a = None
    with open(filename,'rb')as f:
        a = pickle.load(f)
    return a